package com.wlxk.base.common.query;

import lombok.Data;

import java.io.Serializable;

/**
 * @author wlxk
 * @since 2021-11-05 09:15:10
 */
@Data
public class WlQuery implements Serializable {

    private static final long serialVersionUID = 5707736999249935242L;

    private static final Integer DEFAULT_PAGE_SIZE = 15;
    private static final Integer MAX_PAGE_SIZE = 5000;

    /**
     * 当前页
     */
    private Integer currentPage;
    /**
     * 页大小
     */
    private Integer pageSize;
    /**
     * 总记录数
     */
    private Integer totalRecord;

    /**
     * id
     */
    private Long id;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 创建时间
     */
    private String updateTime;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 操作人
     */
    private String operator;

    public Integer getTotalRecord() {
        if (null == totalRecord) {
            this.totalRecord = 0;
        }
        return this.totalRecord;
    }

    public Integer getTotalPage() {
        if (getTotalRecord() > 0) {
            return totalRecord / getPageSize() + 1;
        }
        return 0;
    }

    public Integer getPageSize() {
        if (null == this.pageSize || this.pageSize < 0) {
            this.pageSize = DEFAULT_PAGE_SIZE;
        }
        if (this.pageSize > MAX_PAGE_SIZE) {
            this.pageSize = MAX_PAGE_SIZE;
        }
        return this.pageSize;
    }

    public Integer getCurrentPage() {
        if (null == currentPage || currentPage <= 0) {
            currentPage = 1;
        }
        return currentPage;
    }
}
